var prefix = ctx + "module/customerInfo"

$(function() {
	var columns = [
			{
				checkbox : true
			},
			{
				field : 'customerId',
				title : '客户id'
			},
			{
				field : 'name',
				title : '姓名'
			},
			{
				field : 'cellphone',
				title : '手机号码'
			},
			{
				field : 'sex',
				title : '性别',
				formatter : function(value, row, index) {
					if (value == 0) {
						return '<span class="label label-primary">未知</span>';
					} else if (value == 1) {
						return '<span class="label label-success">男</span>';
					} else if (value == 2) {
						return '<span class="label label-danger">女</span>';
					}
				}
			},
			{
				field : 'age',
				title : '年龄'
			},
			{
				field : 'identityNum',
				title : '身份证号码'
			},
			{
				field : 'province',
				title : '地址 ',
				formatter : function(value, row, index) {
					return "<span class='choose'>" + row.province + "-" + row.city + "-"
							+ row.area + "</span>";
				}
			},
			{
				field : 'addressDetail',
				title : '地址详情'
			},
			{
				field : 'createBy',
				title : '负责人'
			},
			{
				field : 'createTime',
				title : '创建时间'
			},
			{
				title : '操作',
				align : 'center',
				formatter : function(value, row, index) {
					var actions = [];
					actions.push('<a class="btn btn-warning btn-sm ' 
							+ detailsFlag 
							+ '" href="#" title="详情" mce_href="#" onclick="details(\'' 
							+ row.customerId 
							+ '\')"><i class="fa fa-search"></i></a> ');
					actions.push('<a class="btn btn-primary btn-sm '
							+ editFlag
							+ '" href="#" title="编辑" mce_href="#" onclick="edit(\''
							+ row.customerId
							+ '\')"><i class="fa fa-edit"></i></a> ');
					actions.push('<a class="btn btn-info btn-sm '
							+ editFlag
							+ '" href="#" title="修改积分" mce_href="#" onclick="editIntegral(\''
							+ row.customerId
							+ '\')"><i class="fa fa-sort"></i></a> ');
					actions.push('<a class="btn btn-warning btn-sm '
							+ removeFlag
							+ '" href="#" title="删除" onclick="remove(\''
							+ row.customerId
							+ '\')"><i class="fa fa-remove"></i></a>');
					return actions.join('');
				}
			} ];
	var url = prefix + "/list";
	$.initTable(columns, url);	
});

/* 客户-新增 */
function add() {
	var url = prefix + '/add';
	layer_showAuto("新增客户", url);
}

/* 客户-修改 */
function edit(customerId) {
	var url = prefix + '/edit/' + customerId;
	layer_showAuto("修改客户", url);
}

/* 客户-积分修改 */
function editIntegral(customerId) {
	var url = prefix + '/editIntegral/' + customerId;
	layer_showAuto("积分修改", url);
}

/* 客户-详情*/
function details(customerId) {
    var url = prefix + '/details/' + customerId;
    layer_showAuto("客户信息详情", url);
}

// 单条删除
function remove(id) {
	$.modalConfirm("确定要删除选中客户吗？", function() {
		_ajax(prefix + "/remove/" + id, "", "post");
	})
}

// 批量删除
function batchRemove() {
	var rows = $.getSelections("customerId");
	if (rows.length == 0) {
		$.modalMsg("请选择要删除的数据", "warning");
		return;
	}
	$.modalConfirm("确认要删除选中的" + rows.length + "条数据吗?", function() {
		_ajax(prefix + '/batchRemove', {
			"ids" : rows
		}, "post");
	});
}
/*	onload = function(){
		 var chooselist =  document.getElementsByClassName('choose');
		 for(var i=0;i<chooselist.length;i++){		     
			 var Text =  chooselist[i].innerText.replace(/-/g,"")
			 chooselist[i].innerText = Text
			 if(chooselist[i].innerText=='请选择请选择请选择'){
				 chooselist[i].innerText = '-';
			 }
		 }
	}*/
		
	
	

